//
// Created by redcat1 on 12.05.2024.
//

#include "data_generator.h"
#include <random>

//
int GetRandomInt(int min, int max)
{
  return min + std::rand() / ((RAND_MAX + 1u) / (max + 1u - min));
}

//
double GetRandomDouble(double min, double max, int significantDigits)
{
  double value = 0.0;
  int degree = significantDigits;
  while (degree != 0)
  {
    value += GetRandomInt(0, 9) * pow(10, --degree);
  }

  const double scale = (max - min) / pow(10, significantDigits);
  return min + value * scale;
}

//
Rectangle GetRandomRectangle()
{
  Rectangle rectangle;
  rectangle.width = GetRandomDouble(-1, 10, 3);
  rectangle.length = GetRandomDouble(rectangle.width, 10, 3);
  return rectangle;
}

//
Circle GetRandomCircle()
{
  Circle circle;
  circle.radius = GetRandomDouble(-1, 10, 3);
  return circle;
}

//
RightTriangle GetRandomRightTriangle()
{
  RightTriangle rightTriangle;
  rightTriangle.leg1 = GetRandomDouble(-1, 10, 3);
  rightTriangle.leg2 = GetRandomDouble(rightTriangle.leg1, 10, 3);
  return rightTriangle;
}
